﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using QuartzExt;
using QuartzExt.JobTypes;

namespace QuartzExtTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var jobInfo = new JobInfo()
            {
                Name = "添加测试数据",
                AssemblyFile =  Path.Combine(Environment.CurrentDirectory,"QuartzExt.dll"),
                JobType = typeof(SqlServerJob).FullName,
                TriggerType = TriggerType.Simple,
                Interval = 5,
                AttachParam = JsonConvert.SerializeObject(new SqlServerJobParam()
                {
                    CommandText = "INSERT INTO [Users](UserName,UserNo) VALUES('N' + CONVERT(VARCHAR(20),GETDATE(),120),CONVERT(VARCHAR(20),GETDATE(),120))",
                    CommandType = CommandType.Text,
                    ConnectionString = "data source=.;initial catalog=test;User Id=wjq;Password=123456;min pool size=3;max pool size=200;Connect Timeout=60"
                })
            };
            QuaztzManager.Start(jobInfo);
            QuaztzManager.SetConsumer(s =>
                Console.WriteLine($"{s.Time:yyyy-MM-dd HH:mm:ss}" +s.Message)
            );
            string key  = null;
            while (true)
            {
                key = Console.ReadLine();              
                if (key == "quit")
                {
                    break;
                }
                switch (key)
                {
                    case "pause":
                        QuaztzManager.Pause(jobInfo.Group,jobInfo.Name);
                        continue;
                }
            }
            Console.Read();
        }
    }
}
